home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / GraphicsGX / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  4.8 KB  |  170 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. // ----- Framework Layer -----
  14. #ifndef FWCONTXT_H
  15. #include "FWContxt.h"            // FW_CViewContext
  16. #endif
  17.  
  18. #ifndef FWPRHDLR_H
  19. #include "FWPrHdlr.h"            // FW_CPrintHandler
  20. #endif
  21.  
  22. // ----- Graphic Includes -----
  23. #ifndef FWRECT_H
  24. #include <FWRect.h>                // FW_CRect
  25. #endif
  26.  
  27. #ifndef FWRECSHP_H
  28. #include "FWRecShp.h"            // FW_CRectShape
  29. #endif
  30.  
  31. #ifndef FWGXUTIL_H
  32. #include "FWGXUtil.h"            // FW_CGraphicContextGX
  33. #endif
  34.  
  35. // for QuickDraw GX
  36. #ifndef __GXGRAPHICS__
  37. #include <GXGraphics.h>                // GXNewRectangle()
  38. #endif
  39.  
  40. #ifndef __GXENVIRONMENT__
  41. #include <GXEnvironment.h>            // GXNewWindowViewPort()
  42. #endif
  43.  
  44. #include <GXFonts.h>
  45. #include <GXLayout.h>
  46.  
  47.  
  48. //========================================================================================
  49. #ifdef FW_BUILD_MAC
  50. #pragma segment GraphicsGX
  51. #endif
  52.  
  53. //========================================================================================
  54. FW_DEFINE_AUTO(CGraphicsGXFrame)
  55.  
  56. //========================================================================================
  57. CGraphicsGXFrame::CGraphicsGXFrame(Environment* ev, ODFrame* odFrame, 
  58.                                     FW_CPresentation* presentation, CGraphicsGXPart* graphicsgxPart)
  59.   : FW_CFrame(ev, odFrame, presentation, graphicsgxPart)
  60. {
  61.     FW_END_CONSTRUCTOR
  62. }
  63.  
  64. //----------------------------------------------------------------------------------------
  65. CGraphicsGXFrame::~CGraphicsGXFrame()
  66. {
  67.     FW_START_DESTRUCTOR
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. void 
  72. CGraphicsGXFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  73. {
  74.     this->MyDrawWithODF(ev, odFacet, invalidShape);
  75.     {
  76.         FW_CGraphicContextGX gxContext(ev, odFacet, invalidShape);
  77.         this->MyDrawGXBoxes(ev, gxContext);
  78.         this->MyDrawGXText(ev, gxContext);
  79.     }
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. void 
  84. CGraphicsGXFrame::MyDrawWithODF(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  85. {
  86.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  87.     FW_CRect rect(FW_IntToFixed(25), FW_IntToFixed(25), FW_IntToFixed(75), FW_IntToFixed(75) );
  88.     FW_CRectShape rectShape(rect, FW_kFill);
  89.     rectShape.GetInk().SetForeColor(FW_kRGBGreen);
  90.     rectShape.Render(context);
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. void 
  95. CGraphicsGXFrame::MyDrawGXBoxes(Environment* ev, FW_CGraphicContextGX& context)
  96. {
  97.     FW_UNUSED(ev);
  98.     gxRectangle     rectData = {ff(100), ff(100), ff(200), ff(300)};    
  99.     Fixed rotateCenter = ff(150);
  100.     gxShape shape = ::GXNewRectangle(&rectData); 
  101.     context.DrawShape(shape);
  102.  
  103.     ::GXRotateShape(shape, ff(-45), rotateCenter, rotateCenter);
  104.     gxColor myColor;
  105.     myColor.space = gxRGBSpace;
  106.     myColor.profile = NULL;
  107.     myColor.element.rgb.red = 0x8000;
  108.     myColor.element.rgb.green = 0x1000;
  109.     myColor.element.rgb.blue = 0xE000;
  110.     ::GXSetShapeColor(shape, &myColor);
  111.     context.DrawShape(shape);
  112.  
  113.     ::GXDisposeShape(shape);
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. void 
  118. CGraphicsGXFrame::MyDrawGXText(Environment* ev, FW_CGraphicContextGX& context)
  119. {
  120.     FW_UNUSED(ev);
  121.     gxPoint position = {ff(50), ff(50)};
  122.     gxShape textShape = 
  123.             ::GXNewText(20, (unsigned char*)"     The ffish in GX", &position);
  124.  
  125.     gxStyle textStyle = ::GXNewStyle();
  126.     gxRunFeature runFeature[1];
  127. //        runFeature[0].featureType = ligaturesType;
  128.     runFeature[0].featureSelector = gxNoLigatureSplits;
  129.     ::GXSetStyleRunFeatures(textStyle, 1, runFeature);
  130.     ::GXSetStyleTextSize(textStyle, ff(36));
  131.     ::GXSetShapeStyle(textShape, textStyle);
  132.  
  133.     gxFont aFont; 
  134.     long numFonts = ::GXFindFonts(nil, gxFullFontName, gxMacintoshPlatform, 
  135.                     gxRomanScript, gxEnglishLanguage, strlen("Apple Chancery"), 
  136.                     (const unsigned char*)"Apple Chancery", 1, 1, &aFont);
  137.     ::GXSetShapeFont(textShape, aFont);
  138.     for (short i = 0; i <=3; i++)
  139.     {
  140.         ::GXRotateShape(textShape, ff(i*15), position.x, position.y);
  141.         context.DrawShape(textShape);
  142.     }
  143.     ::GXDisposeShape(textShape);
  144. }
  145.  
  146. //------------------------------------------------------------------------------
  147. FW_CPrintHandler* 
  148. CGraphicsGXFrame::NewPrintHandler(Environment* ev)
  149. {
  150.     FW_CPart* part = GetPart(ev);
  151.     return new FW_CPrintHandler(part, this);
  152. }
  153.  
  154. //------------------------------------------------------------------------------
  155. FW_Boolean 
  156. CGraphicsGXFrame::IsCurrentlyPrintable(Environment* ev) const
  157. {
  158.     FW_UNUSED(ev);
  159.     return true;
  160. }
  161.  
  162. //------------------------------------------------------------------------------
  163. void 
  164. CGraphicsGXFrame::GetPrintContentExtent(Environment* ev, FW_CPoint& extent) const
  165. {
  166.     FW_CRect frameRect = this->GetBounds(ev);
  167.     extent = frameRect.Size();
  168. }
  169.  
  170.